<template>
  <video :id="`load-video-${props.id}`" :src="props.src" :muted="true" :controls="false" :show-center-play-btn="false" @loadedmetadata="handleLoad" />
</template>
<script setup lang="ts">
import { isWeixin } from "@/utils"
import { onLoad } from "@dcloudio/uni-app"

/** emit */
const emits = defineEmits<{
  /** 筛选变更 */
  load: [data: any]
}>()

/** props */
const props = withDefaults(defineProps<{
  /** 视频id */
  id: string
  // 视频地址
  src: string
}>(), {})

// 视频加载
const handleLoad = (event: any) => {
  if (isWeixin) {
    uni.createVideoContext(`load-video-${props.id}`).pause()
  }
  emits("load", event)
}

onLoad(() => {
  // 判断是否在微信中打开
  if (isWeixin) {
    WeixinJSBridge.invoke("getNetworkType", {}, () => {
      uni.createVideoContext(`load-video-${props.id}`).play()
    })
  }
})
</script>